<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:fragment="head">
	<base th:href="@{/}">
	<meta charset="utf-8">
	<title>新增</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="static/layui/css/layui.css" media="all" />
	<script type="text/javascript" src="static/layui/layui.js"></script>
	<script type="text/javascript" src="/static/plugin/jquery/jquery-3.2.1.min.js"></script>
	<style type="text/css">
		.layui-form-label {
		    white-space: nowrap;
		    width: 120px;
		    color: gray;
		}
	</style>
</head>
<body>
<div class="layui-fluid">
	<div class="layui-card">
		<!-- 内容区 -->
		<div class="layui-card-body">
			<form class="layui-form" id="form" action="" lay-filter="demo-val-filter">
				<div class="layui-form-item" style="margin-top: 20px;">
					<div class="layui-inline">
						<label class="layui-form-label"><span style="color: red">*</span>产品编码</label>
						<div class="layui-input-inline">
							<input name="cinvcode" id="cinvcode" class="layui-input" lay-verify="required" readonly>
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label"><span style="color: red">*</span>产品名称</label>
						<div class="layui-input-inline">
							<input name="cinvname" class="layui-input" lay-verify="required" readonly>
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label"><span style="color: red">*</span>是否来料</label>
						<div class="layui-input-inline">
							<input type="checkbox" name="sfll" value="1" lay-skin="switch" title="否|是">
						</div>
					</div>
				</div>
				<div class="layui-form-item" style="margin-top: 20px;">
					<div class="layui-inline">
						<label class="layui-form-label"><span style="color: red">*</span>批号</label>
						<div class="layui-input-inline">
							<input name="cbatch" lay-verify="required" class="layui-input" >
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label"><span style="color: red">*</span>订单数量</label>
						<div class="layui-input-inline">
							<input type="number" name="qty" min="0" class="layui-input" lay-verify="required" >
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label"><span style="color: red">*</span>是否实物</label>
						<div class="layui-input-inline">
							<input type="checkbox" name="sfsw" value="1" lay-skin="switch" title="否|是">
						</div>
					</div>
				</div>
				<div class="layui-form-item" style="margin-top: 20px;">
					<div class="layui-inline">
						<label class="layui-form-label"><span style="color: red">*</span>类型</label>
						<div class="layui-input-inline">
							<select name="type" lay-verify="required">
								<option value="借机测试">借机测试</option>
								<option value="借人测试">借人测试</option>
								<option value="借场地测试">借场地测试</option>
								<option value="购销">购销</option>
								<option value="开发测试">开发测试</option>
							</select>
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label"><span style="color: red">*</span>来料日期</label>
						<div class="layui-input-inline">
							<input name="llrq" class="layui-input" lay-verify="required"  id="ID-laydate-demo" placeholder="yyyy-MM-dd">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label"><span style="color: red">*</span>产值计算类型</label>
						<div class="layui-input-inline">
							<select name="czjslx" lay-verify="required">
								<option value="按工序次数">按工序次数</option>
								<option value="按批次">按批次</option>
								<option value="按试验时间">按试验时间</option>
								<option value="按借机时间">按借机时间</option>
							</select>
						</div>
					</div>
				</div>
				<div class="layui-form-item" style="margin-top: 20px;">
<!--					<div class="layui-inline">-->
<!--						<label class="layui-form-label">设备类型</label>-->
<!--						<div class="layui-input-inline">-->
<!--							<input name="sblx" lay-verify="required" class="layui-input">-->
<!--						</div>-->
<!--					</div>-->
					<div class="layui-inline">
						<label class="layui-form-label">特殊备注</label>
						<div class="layui-input-inline">
							<input name="tsbz" class="layui-input">
						</div>
					</div>
					<div class="layui-inline">
						<label class="layui-form-label"></label>
						<button type="submit" style="display: none" id="submit" class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
				</div>
			</form>
		</div>
	</div>
	<script type="text/javascript" src="/static/layui/module/tableSelect.js"></script>
	<script type="text/javascript" src="/static/plugin/snowflake/snowflake.js"></script>
	<script type="text/javascript" th:inline="javascript">
		let sign = false;
		const snowflake = new Snowflake();
		layui.use(['layer','jquery','table','element','form','laydate','tableSelect'],function(){
			let layer = layui.layer,
					table = layui.table,
					form = layui.form,
					laydate = layui.laydate,
					$ = layui.jquery,
					tableSelect = layui.tableSelect,
					element = layui.element;

			// 渲染
			laydate.render({
				elem: '#ID-laydate-demo'
			});

			tableSelect.render({
				elem: '#cinvcode',
				searchKey: 'key',
				searchPlaceholder: '产品编码/产品名称',
				checkedKey: 'code',
				table: {
					url: '/manage/product/list'
					,method: 'post'
					,cols: [
						[
							{ type: 'radio' },
							{ field: 'code', title: '产品编码' },
							{ field: 'name', title: '产品名称' },
						]
					]
				},
				done: function (elem, data) {
					let da = data.data[0]
					elem.val(da.code)
					$('input[name=cinvname]').val(da.name)
				}
			})

			form.on('submit(demo1)', function(data){
				sign = true
				return false; // 阻止默认 form 跳转
			});

		})
		
		function fromData() {

			$('#submit').click();

			let data = layui.form.val('demo-val-filter');
			if (!data.sfsw){
				data.sfsw = 0
			}
			if (!data.sfll){
				data.sfll = 0
			}
			if (data.qty <= 0){
				top.layer.msg("订单数量不能是0")
				sign = false
			}
			data.id = snowflake.nextId();
			data.sign = sign
			return data
		}
	</script>
</div>
</body>
</html>